home *** CD-ROM | disk | FTP | other *** search
/ Mac Format 1994 October / Macformat17.cdr / Shareware City / Developers / shutdown-fx-201-c / sfx ƒ / sfx control app ƒ / sfx code ƒ / sfx meat.c < prev    next >
Text File  |  1994-07-11  |  9KB  |  348 lines

  1. /**********************************************************************\
  2.  
  3. File:        sfx meat.c
  4.  
  5. Purpose:    This module handles the fade modules folder: setting up
  6.             the two lists based on the initial information, setting
  7.             information of fades.
  8.  
  9. This program is free software; you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation; either version 2 of the License, or
  12. (at your option) any later version.
  13.  
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. GNU General Public License for more details.
  18.  
  19. You should have received a copy of the GNU General Public License
  20. along with this program in a file named "GNU General Public License".
  21. If not, write to the Free Software Foundation, 675 Mass Ave,
  22. Cambridge, MA 02139, USA.
  23.  
  24. \**********************************************************************/
  25.  
  26. #include "Folders.h"
  27. #include "sfx meat.h"
  28. #include "sfx install.h"
  29. #include "sfx gestalt.h"
  30. #include "sfx lists.h"
  31. #include "main.h"
  32. #include "timing.h"
  33. #include "util.h"
  34. #include "file interface.h"
  35.  
  36. struct QDGlobals
  37. {
  38.     char privates[76];
  39.     long randSeed;
  40.     BitMap screenBits;
  41.     Cursor arrow;
  42.     Pattern dkGray;
  43.     Pattern ltGray;
  44.     Pattern gray;
  45.     Pattern black;
  46.     Pattern white;
  47.     GrafPtr thePort;
  48.     long    end;
  49. };
  50.  
  51. typedef struct QDGlobals QDGlobals;
  52. typedef pascal short (*FadeProcPtr)(Rect boundsRect, Pattern *thePattern);
  53.  
  54. long            gModuleDirID;
  55. short            gModuleVRefNum;
  56.  
  57. /* internal procedures for use in sfx meat.c only */
  58. static OSErr TouchFolder(FSSpec fs);
  59. static void DoTheDangFade(FadeProcPtr theFade);
  60.  
  61.  
  62. enum ErrorTypes SetUpLists(ListHandle usedList, ListHandle unusedList)
  63. {
  64.     CInfoPBRec        pb;
  65.     OSErr            isHuman;
  66.     Str255            theName;
  67.     long            systemDirID;
  68.     short            numModules;
  69.     short            i;
  70.     Boolean            noModules;
  71.     
  72.     isHuman=FindFolder(kOnSystemDisk, kSystemFolderType, kDontCreateFolder, &gModuleVRefNum,
  73.                 &systemDirID);                    /* find system folder */
  74.     if (isHuman!=noErr)
  75.         return kCantFindSystemFolder;
  76.     
  77.     pb.dirInfo.ioCompletion=0L;
  78.     pb.dirInfo.ioNamePtr=MODULE_FOLDER;
  79.     pb.dirInfo.ioVRefNum=gModuleVRefNum;
  80.     pb.dirInfo.ioFDirIndex=0;             /* very important */
  81.     pb.dirInfo.ioDrDirID=systemDirID;
  82.     isHuman=PBGetCatInfo(&pb, FALSE);    /* get info on "MSG Fades ƒ" folder */
  83.     if (isHuman!=noErr)
  84.         return kCantFindModuleFolder;
  85.     
  86.     gModuleDirID=pb.dirInfo.ioDrDirID;
  87.     numModules=pb.dirInfo.ioDrNmFls;
  88.     
  89.     MyClearAllCells(usedList);
  90.     MyClearAllCells(unusedList);
  91.     
  92.     noModules=TRUE;
  93.     
  94.     for (i=1; i<=numModules; i++)
  95.     {
  96.         pb.hFileInfo.ioCompletion=0L;
  97.         pb.hFileInfo.ioNamePtr=theName;
  98.         pb.hFileInfo.ioVRefNum=gModuleVRefNum;
  99.         pb.hFileInfo.ioFDirIndex=i;
  100.         pb.hFileInfo.ioDirID=gModuleDirID;
  101.         isHuman=PBGetCatInfo(&pb, FALSE);
  102.         if ((isHuman==noErr) && (!(pb.hFileInfo.ioFlAttrib&0x10)) &&
  103.             (pb.hFileInfo.ioFlFndrInfo.fdCreator==CREATOR))
  104.         {
  105.             /* got a fade module, now find out if it's used or unused and add to list */
  106.             
  107.             if (pb.hFileInfo.ioFlFndrInfo.fdType==USED_TYPE)
  108.             {
  109.                 MyAddStr255ToList(usedList, theName);
  110.                 noModules=FALSE;
  111.             }
  112.             else if (pb.hFileInfo.ioFlFndrInfo.fdType==UNUSED_TYPE)
  113.             {
  114.                 MyAddStr255ToList(unusedList, theName);
  115.                 noModules=FALSE;
  116.             }
  117.         }
  118.     }
  119.     
  120.     return noModules ? kNoModulesInFolder : allsWell;
  121. }
  122.  
  123. enum ErrorTypes DoTheDemoFade(ListHandle theList)
  124. {
  125.     Cell            theCell;
  126.     Str255            theName;
  127.     Handle            theProcHandle;
  128.     FadeProcPtr        theFade;
  129.     unsigned long    theSize;
  130.     FSSpec            fs;
  131.     short            oldRefNum, newRefNum;
  132.     Boolean            alreadyOpen;
  133.     OSErr            theResError;
  134.     
  135.     if (!MyGetFirstSelectedCell(theList, &theCell))
  136.         return allsWell;
  137.     
  138.     while (LGetSelect(TRUE, &theCell, theList))
  139.     {
  140.         MyGetCellData(theList, theCell, theName);
  141.         LNextCell(FALSE, TRUE, &theCell, theList);
  142.         MyMakeFSSpec(gModuleVRefNum, gModuleDirID, theName, &fs);
  143.         theResError=OpenTheResFile(&fs, &oldRefNum, &newRefNum, &alreadyOpen);
  144.         if (theResError!=noErr)
  145.             return kCantOpenModule;
  146.         
  147.         theProcHandle=Get1Resource('PROC', 0);
  148.         if (((theResError=ResError())!=noErr) || (theProcHandle==0L))
  149.             return kModuleDamaged;
  150.         
  151.         if (*theProcHandle==0L)
  152.             LoadResource(theProcHandle);
  153.         if (*theProcHandle==0L)
  154.             return kModuleDamaged;
  155.         
  156.         theProcHandle=StripAddress(theProcHandle);
  157.         *theProcHandle=StripAddress(*theProcHandle);
  158.         
  159.         HLock(theProcHandle);
  160.         theFade=NewPtrSys(theSize=GetHandleSize(theProcHandle));
  161.         if (theFade==0L)
  162.         {
  163.             ReleaseResource(theProcHandle);
  164.             return kNoMemoryInSystemHeap;
  165.         }
  166.         
  167.         theFade=StripAddress(theFade);
  168.         
  169.         Mymemcpy(theFade, *theProcHandle, theSize);
  170.         ReleaseResource(theProcHandle);
  171.         theProcHandle=0L;
  172.         CloseTheResFile(oldRefNum, newRefNum, alreadyOpen);
  173.         DoTheDangFade(theFade);
  174.         DisposePtr(theFade);
  175.         theFade=0L;
  176.         while (HandleSingleEvent());
  177.     }
  178.     
  179.     return allsWell;
  180. }
  181.  
  182. void DoTheDangFade(FadeProcPtr theFade)
  183. {
  184.     short            oldMenuBarHeight;
  185.     long            oldA5;
  186.     QDGlobals        qd;                /* our QD globals. */
  187.     GrafPort        gp;                /* our grafport. */
  188.     GrafPtr            savePort;
  189.     short            whichWipe;
  190.     THz                saveZone;
  191.     unsigned long    temp;
  192.     
  193.     GetPort(&savePort);
  194.     oldMenuBarHeight=MBarHeight;
  195.     MBarHeight=0;
  196.     DrawMenuBar();
  197.  
  198.     /* get a value for A5, a structure that mirrors qd globals. */
  199.     oldA5 = SetA5((long)&qd.end);
  200.     InitGraf(&qd.thePort);
  201.     OpenPort(&gp);
  202.     
  203.     HideCursor();
  204.     
  205.     saveZone=GetZone();
  206.     SetZone(SysZone);
  207.  
  208.     theFade(gp.portRect, &qd.black);
  209.     
  210.     SetZone(saveZone);
  211.     
  212.     MBarHeight=oldMenuBarHeight;
  213.     ShowCursor();
  214.     ObscureCursor();
  215.     
  216.     ClosePort(&gp);
  217.     SetA5(oldA5);
  218.     SetPort(savePort);
  219.     
  220.     StartTiming();
  221.     TimeCorrection(10);
  222.     
  223.     DrawMenuBar();
  224.     PaintOne(0L, GetGrayRgn());
  225.     PaintBehind(WindowList, GetGrayRgn());
  226. }
  227.  
  228. enum ErrorTypes DoTheInstall(WindowDataHandle theData, ListHandle usedList,
  229.     ListHandle unusedList)
  230. {
  231.     Cell            theCell;
  232.     CInfoPBRec        pb;
  233.     OSErr            isHuman;
  234.     Str255            theName;
  235.     GrafPtr            curPort;
  236.     FSSpec            fs;
  237.     
  238.     if (!MyGetFirstSelectedCell(unusedList, &theCell))
  239.         return allsWell;
  240.     
  241.     while (LGetSelect(TRUE, &theCell, unusedList))
  242.     {
  243.         MyGetCellData(unusedList, theCell, theName);
  244.         LNextCell(FALSE, TRUE, &theCell, unusedList);
  245.         pb.hFileInfo.ioCompletion=0L;
  246.         pb.hFileInfo.ioNamePtr=theName;
  247.         pb.hFileInfo.ioVRefNum=gModuleVRefNum;
  248.         pb.hFileInfo.ioFDirIndex=0;
  249.         pb.hFileInfo.ioDirID=gModuleDirID;
  250.         isHuman=PBGetCatInfo(&pb, FALSE);
  251.         if (isHuman!=noErr)
  252.             return kCantGetModuleInfo;
  253.         
  254.         pb.hFileInfo.ioDirID=gModuleDirID;
  255.         pb.hFileInfo.ioFlFndrInfo.fdType=USED_TYPE;
  256.         isHuman=PBSetCatInfo(&pb, FALSE);
  257.         if (isHuman!=noErr)
  258.             return kCantSetModuleInfo;
  259.     }
  260.     
  261.     MyMakeFSSpec(gModuleVRefNum, gModuleDirID, theName, &fs);
  262.     TouchFolder(fs);
  263.     
  264.     LDoDraw(FALSE, usedList);
  265.     LDoDraw(FALSE, unusedList);
  266.     SetUpLists(usedList, unusedList);
  267.     LDoDraw(TRUE, usedList);
  268.     LDoDraw(TRUE, unusedList);
  269.     GetPort(&curPort);
  270.     SetPort((**unusedList).port);
  271.     EraseRect(&((**unusedList).rView));
  272.     SetPort(curPort);
  273.     
  274.     return allsWell;
  275. }
  276.  
  277. enum ErrorTypes DoTheRemove(WindowDataHandle theData, ListHandle usedList,
  278.     ListHandle unusedList)
  279. {
  280.     Cell            theCell;
  281.     CInfoPBRec        pb;
  282.     OSErr            isHuman;
  283.     Str255            theName;
  284.     GrafPtr            curPort;
  285.     FSSpec            fs;
  286.     
  287.     if (!MyGetFirstSelectedCell(usedList, &theCell))
  288.         return allsWell;
  289.     
  290.     while (LGetSelect(TRUE, &theCell, usedList))
  291.     {
  292.         MyGetCellData(usedList, theCell, theName);
  293.         LNextCell(FALSE, TRUE, &theCell, usedList);
  294.         pb.hFileInfo.ioCompletion=0L;
  295.         pb.hFileInfo.ioNamePtr=theName;
  296.         pb.hFileInfo.ioVRefNum=gModuleVRefNum;
  297.         pb.hFileInfo.ioFDirIndex=0;
  298.         pb.hFileInfo.ioDirID=gModuleDirID;
  299.         isHuman=PBGetCatInfo(&pb, FALSE);
  300.         if (isHuman!=noErr)
  301.             return kCantGetModuleInfo;
  302.         
  303.         pb.hFileInfo.ioDirID=gModuleDirID;
  304.         pb.hFileInfo.ioFlFndrInfo.fdType=UNUSED_TYPE;
  305.         isHuman=PBSetCatInfo(&pb, FALSE);
  306.         if (isHuman!=noErr)
  307.             return kCantSetModuleInfo;
  308.     }
  309.     
  310.     MyMakeFSSpec(gModuleVRefNum, gModuleDirID, theName, &fs);
  311.     TouchFolder(fs);
  312.     
  313.     LDoDraw(FALSE, usedList);
  314.     LDoDraw(FALSE, unusedList);
  315.     SetUpLists(usedList, unusedList);
  316.     LDoDraw(TRUE, usedList);
  317.     LDoDraw(TRUE, unusedList);
  318.     GetPort(&curPort);
  319.     SetPort((**usedList).port);
  320.     EraseRect(&((**usedList).rView));
  321.     SetPort(curPort);
  322.     
  323.     return allsWell;
  324. }
  325.  
  326. OSErr TouchFolder(FSSpec fs)
  327. {
  328.     CInfoPBRec        pb;
  329.     OSErr            isHuman;
  330.     
  331.     pb.dirInfo.ioCompletion=0L;
  332.     pb.dirInfo.ioVRefNum=fs.vRefNum;
  333.     pb.dirInfo.ioDrDirID=fs.parID;
  334.     pb.dirInfo.ioNamePtr=fs.name;
  335.     pb.dirInfo.ioFDirIndex=0;
  336.     if ((isHuman=PBGetCatInfo(&pb, FALSE))!=noErr)
  337.     {
  338.         FlushVol(0L, fs.vRefNum);
  339.         pb.dirInfo.ioDrDirID=pb.dirInfo.ioDrParID;
  340.         pb.dirInfo.ioFDirIndex=0;
  341.         GetDateTime(&(pb.dirInfo.ioDrMdDat));
  342.         isHuman=PBSetCatInfo(&pb, FALSE);
  343.         FlushVol(0L, fs.vRefNum);
  344.     }
  345.     
  346.     return isHuman;
  347. }
  348.